﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Newtonsoft.Json;
using Tisonet.Dobrak.Domain.Models;

namespace Tisonet.Dobrak.Client.WP8.Services.Projections
{
    public class EmbeddedProjectionsProvider : IProjectionsProvider
    {
        public void GetProjectionsAsync(Action<IEnumerable<Projection>> onReady)
        {
            var resource = Application.GetResourceStream(new Uri(@"Tisonet.Dobrak.Client.WP8;component/Resources/Program.txt", UriKind.Relative));

            using (var streamReader = new StreamReader(resource.Stream))
            {
                using (var jsonReader = new JsonTextReader(streamReader))
                {
                    var serializer = new JsonSerializer();
                    var projections = serializer.Deserialize<IEnumerable<Projection>>(jsonReader);
                   
                    if (onReady != null)
                    {
                        onReady(projections);
                    }
                }
            }
           
        }
    }
}
